home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8089 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: rcogate.rco.qc.ca!altitude!obelix
  2. From: dtaylor@pifus.com (David Taylor)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Compiler Bug - can call private constructors.
  5. Date: Wed, 14 Feb 96 13:40:44 GMT
  6. Organization: Pifus Inc.
  7. Message-ID: <4fsork$bef@tandem.CAM.ORG>
  8. References: <311a149f.8353477@hector> <4fnk8n$17e@daffodil.InfoChan.COM>
  9. NNTP-Posting-Host: pifus.hip.cam.org
  10. X-Newsreader: News Xpress 2.0 Beta #0
  11.  
  12. In article <4fnk8n$17e@daffodil.InfoChan.COM>, alanj@infochan.com (Alan Johnston) wrote:
  13. >Kenn@owl-uk.co.uk (Ken Nicolson) wrote:
  14. >>>>>> SAMPLE CODE REPRODUCING PROBLEM
  15. >
  16. >>#include <stdio.h>
  17. >>#include <iostream.h>
  18. >
  19. >>class FOOBAR
  20. >>{
  21. >>private:
  22. >>    FOOBAR()
  23. >>    {
  24. >>        cout << "I've called a private constructor!\n";
  25. >>    }
  26. >>};
  27. >
  28. >
  29. >>FOOBAR foobar()
  30. >>{
  31. >>//  FOOBAR b; SYNTAX ERROR, as expected
  32. >>    return FOOBAR( );   // This is wrong
  33. >>}
  34. >
  35. >Perhaps the problem stems from the fact that 'return FOOBAR() '
  36. >actually calls the copy constructor.  Since you haven't declared a
  37. >private copy constructor, the compiler is making one for you, and it
  38. >is public.  Try declaring a private copy constructor:
  39. >FOOBAR(const FOOBAR&);
  40. >
  41.  
  42. Actually, would not the default constructor be called first, creating a 
  43. temporary, and then the temporary passed to the copy constructor to complete 
  44. the return call?  After all, the copy constructor needs something to copy.
  45.  
  46. Dave
  47. dtaylor@pifus.com
  48.